﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ProjectHopur23.Models;

namespace ProjectHopur23.Repositories
{
	public class Repository : IRepository
	{
		#region Variables
		private DBDataContext db = new DBDataContext();
		#endregion

		#region Functions
		public IEnumerable<Game> GetAllGames()
		{
			return db.games;
		}

		public IEnumerable<ActiveGame> GetAllActiveGames()
		{
			return db.activeGames;
		}

		public IEnumerable<Player> GetAllPlayers()
		{
			return db.players;
		}

		public IEnumerable<UserProfile> GetAllUsers()
		{
			return db.userProfiles;
		}

		public IEnumerable<TicTacToeState> GetAllTicTacToeStates()
		{
			return db.ticTacToeStates;
		}

		public IEnumerable<LudoState> GetAllLudoStates()
		{
			return db.ludoStates;
		}

		public IEnumerable<Invite> GetAllInvites()
		{
			return db.invites;
		}

		public IEnumerable<DieValue> GetAllDieValues()
		{
			return db.dieValues;
		}

		public IEnumerable<Comment> GetAllComments()
		{
			return db.comments;
		}

		public void AddGame(Game g)
		{
			db.games.Add(g);
		}

		public void AddActiveGame(ActiveGame ag)
		{
			db.activeGames.Add(ag);
		}

		public void AddPlayer(Player p)
		{
			db.players.Add(p);
		}

		/*public void AddUser(UserProfile u)
		{
			db.userProfiles.Add(u);
		}*/

		public void AddTicTacToeState(TicTacToeState t)
		{
			db.ticTacToeStates.Add(t);
		}

		public void AddLudoState(LudoState l)
		{
			db.ludoStates.Add(l);
		}

		public void AddInvite(Invite i)
		{
			db.invites.Add(i);
		}

		public void AddDieValue(DieValue d)
		{
			db.dieValues.Add(d);
		}

		public void AddComment(Comment c)
		{
			db.comments.Add(c);
		}
		
		public void Save()
		{
			try
			{
				db.SaveChanges();
			}
			catch(Exception e)
			{
				System.Diagnostics.Debug.WriteLine("An error ocurred, changes cannot be saved");
				System.Diagnostics.Debug.WriteLine("ErrorMessage: " + e.Message);
			}
		}
		#endregion
	}
}
